package com.ninong.ker.common.tools;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

public class PropertyUtil {


    /**
     * 根据Name获取Property
     *
     * @param key
     * @return
     */
    public static String getProperty(String key) {
        HttpServletRequest request = CmdAdminTools.getHttpServletRequest();
        String language = request.getHeader("language");
        InputStream stream = PropertyUtil.class.getResourceAsStream("/i18n/messages_" + language + ".properties");
        Properties p = new Properties();
        try {
            p.load(new InputStreamReader(stream,"UTF-8"));
            return p.getProperty(key);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
